﻿# coding=utf-8
# 2024/2/26: 首个版本
# 2025/7/21: 使用类型注解。优化to_general_sample

import bi_common as bi
from enum import Enum
from typing import List, Any


class WalkerControl:
    def __init__(self):
        self.time: float = 0.0  # [s] Time offset in session / Session内的相对时间
        self.request_control: bool = False  # Weather to request control / 是否请求控制
        self.heading: float = 0.0  # [deg] Heading of moving, 0 as north, CCW is positive / 行进朝向，0为正北，逆时针为正
        self.speed: float = 0.0  # [KPH] Moving speed, 0 is static / 移动速度，0为静止

    # Convert to general sample for output / 转通用样本，用于样本输出
    def to_general_sample(self, channel: int) -> Any:
        output = bi.agency.create_general_sample()
        output.protocol = 'walker-control-v1@' + str(channel)
        output.time = self.time
        output.significant = 3
        
        values: List[float | str | None] = [None] * 3
        values[0] = self.request_control
        values[1] = self.heading
        values[2] = self.speed
        
        output.values = values
        return output
